﻿using System;
using System.Linq.Expressions;
using System.Web.Mvc;
using System.Web.Routing;
using ExpressionHelper = Microsoft.Web.Mvc.Internal.ExpressionHelper;

namespace NHCourse.Controllers
{
   public abstract class AppController : Controller
   {
      protected ActionResult RedirectTo<T>(Expression<Action<T>> action) where T : Controller
      {
         return RedirectToRoute(ExpressionHelper.GetRouteValuesFromExpression(action));
      }

      protected string GetUrl<TController>(Expression<Action<TController>> action) where TController : Controller
      {
         return GetUrl(ExpressionHelper.GetRouteValuesFromExpression(action));
      }

      protected string GetUrl(RouteValueDictionary routeValues)
      {
         return UrlHelper.GenerateUrl("", null, null, routeValues, RouteTable.Routes, ControllerContext.RequestContext, false);
      }
   }
}